package redpacket.mq;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import redpacket.config.RabbitConfig;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Component
@RequiredArgsConstructor
public class GrabProducer {

    private final RabbitTemplate rabbitTemplate;

    public void send(Long packetId, Long userId, BigDecimal amount) {
        Map<String, Object> msg = new HashMap<>();
        msg.put("packetId", packetId);
        msg.put("userId", userId);
        msg.put("amount", amount.toPlainString());
        msg.put("ts", System.currentTimeMillis());
        rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE, RabbitConfig.GRAB_ROUTING_KEY, msg);
    }
}
